<template>
  <div>
    <el-drawer :visible.sync="drawer" direction="rtl" size="45%" :with-header="false" :width="700">
      <div class="drawer_box">
        <div class="drawer_t">
          <div class="drawer_t_l">
            <img class="drawer_t_l_img" src="/static/skin/herodoo/main/platform/home/img/piliangoumai.png" alt="" />
            查看权益
          </div>
          <img class="drawer_t_r" src="/static/skin/herodoo/main/platform/home/img/guanbi.png" alt=""
            @click="drawer = false" />
        </div>
        <div class="drawer_c">
          <div class="rights" v-if="compileData.TypeID == 2">
            <div>组合权益</div>
            <div class="rightsList">
              <div>自有权益</div>
              <div class="rights_son_box" v-if="alreadyList && alreadyList != false">
                <div class="rights_son" v-for="item in alreadyList" :key="item.ID">
                  <div class="title">{{ item.Name }}</div>
                  <div class="date">
                    使用期限：{{ item.EffectiveTime }} 至 {{ item.ExpireTime }}
                  </div>
                  <div class="repert-box">
                    <div class="repert-left">
                      库存：{{ item.InventoryQuantity }}份 数量: x{{
                        item.EquityCount
                      }}份
                    </div>
                    <div class="repert-right">
                      ¥{{ item.CostPrice }}
                      <span style="color: rgba(201, 201, 201, 1);font-size: 16px;">￥{{ item.SalePrice }}</span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="rightsList">
              <div>已购买权益</div>
              <div class="rights_son_box" v-if="buyList && buyList != false">
                <div class="rights_son" v-for="item in buyList" :key="item.ID">
                  <div class="title">{{ item.ProductFlagListName }}</div>
                  <div class="date">
                    使用期限：{{ item.EffectiveTime }} 至 {{ item.ExpireTime }}
                  </div>
                  <div class="repert-box">
                    <div class="repert-left">
                      库存：{{ item.InventoryQuantity }}份 数量: x{{
                        item.EquityCount
                      }}份
                    </div>
                    <div class="repert-right">
                      ¥{{ item.CostPrice }}
                      <span style="color: rgba(201, 201, 201, 1);font-size: 16px;">￥{{ item.SalePrice }}</span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="rights">
            <div>基础信息</div>
            <div class="rightsList">
              <div>权益标题</div>
              <div>{{ compileData.Name }}</div>
            </div>
            <div class="rightsList" v-if="compileData.TypeID == 1">
              <div>公司名称</div>
              <div>{{ compileData.CompanyName }}</div>
            </div>
            <div class="rightsList" v-if="compileData.TypeID != 2">
              <div>产品类型</div>
              <div>{{ compileData.ProductFlagListName }}</div>
            </div>

            <div class="rightsList" v-if="compileData.TypeID == 1">
              <div>产品名称</div>
              <div>{{ compileData.ProductName }}</div>
            </div>
            <div class="rightsList" v-if="compileData.TypeID == 1">
              <div>合同编号</div>
              <div class=" flex">
                <div>{{ compileData.ProductCode }}</div>
                <button class="contract-btn" @click="showContract">
                  查看合同
                </button>
              </div>
            </div>
            <div class="rightsList">
              <div>权益标签</div>
              <div class="flex" v-if="compileData.EquityFlagListName">
                <div class="rights-tag" v-for="(item, index) in compileData.EquityFlagListName.split(
                  ','
                )" :key="index" effect="plain">
                  {{ item }}
                </div>
              </div>
            </div>
            <div class="rightsList">
              <div>采购公司权限设置</div>
              <div>
                <div class="flex" v-if="compileData.TransferRuleIDName">
                  <div class="rights-tag auth-tag" v-for="(item,
                    index) in compileData.TransferRuleIDName.split(',')" :key="index" effect="plain">
                    {{ item }}
                  </div>
                </div>
              </div>
            </div>
            <div class="rightsList">
              <div>使用期限</div>
              <div v-if="compileData.TypeID == 2">
                <div class="deadline" v-for="(item, index) in [...alreadyList, ...buyList]" :key="index">
                  <div class="title">{{ item.Name }}</div>
                  <div class="deadline-box">
                    <div>{{ item.EffectiveTime }} 至 {{ item.ExpireTime }}</div>
                  </div>
                </div>
              </div>
              <div v-else>
                <div class="deadline">
                  {{ compileData.EffectiveTime }} 至
                  {{ compileData.ExpireTime }}
                </div>
              </div>
            </div>
            <div class="rightsList">
              <div>库存数量</div>
              <div>{{ compileData.InventoryQuantity }}份</div>
            </div>
            <div class="rightsList">
              <div>起购数量</div>
              <div>{{ compileData.MinimumQuantity }} 份</div>
            </div>
            <div class="rightsList">
              <div>市场价格</div>
              <div>{{ compileData.SalePrice }} 元</div>
            </div>
            <div class="rightsList">
              <div>平台价格</div>
              <div>{{ compileData.CostPrice }} 元</div>
            </div>
            <div class="rightsList rightsContent" v-if="compileData.TypeID == 2">
              <div>服务费</div>
              <div>
                <el-table :data="[...alreadyList, ...buyList]" stripe max-height="250"
                  style="width: 100%;font-size: 1rem;">
                  <el-table-column prop="Name" label="权益名称">
                  </el-table-column>
                  <el-table-column prop="PlatformServiceRate" label="权益平台服务费%">
                    <template slot-scope="scope">
                      <span>{{ scope.row.PlatformServiceRate * 100 }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column prop="EquityServiceRate" label="小程序服务费%">
                    <template slot-scope="scope">
                      <span>{{ scope.row.EquityServiceRate * 100 }}</span>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>
            <div v-else>
              <div class="rightsList">
                <div>权益平台服务费%</div>
                <div>{{ compileData.PlatformServiceRate * 100 }}</div>
              </div>
              <div class="rightsList">
                <div>小程序服务费%</div>
                <div>{{ compileData.EquityServiceRate * 100 }}</div>
              </div>
            </div>
            <div class="rightsList">
              <div>让利积分</div>
              <div>{{ compileData.Integral }} 分</div>
            </div>
            <div class="rightsList">
              <div>权益平台结算价格</div>
              <div>{{ toPlatformPrice() }}元</div>
            </div>
            <div class="rightsList">
              <div>小程序结算价格</div>
              <div>{{ toEquityPrice() }}元</div>
            </div>
            <div class="rightsList">
              <div>是否允许在其他国企、民企平台进行售卖</div>
              <div>{{ compileData.IsOpenSale ? "是" : "否" }}</div>
            </div>

            <div class="rightsList" v-if="compileData.TypeID == 1">
              <div>使用地址</div>
              <div>{{ compileData.Address }}</div>
            </div>
            <div class="rightsList rightsContent" v-if="compileData.TypeID == 2">
              <div>使用人数</div>
              <div>
                <el-table :data="[...alreadyList, ...buyList]" stripe max-height="250"
                  style="width: 100%;font-size: 1rem;">
                  <el-table-column prop="Name" label="权益名称">
                  </el-table-column>
                  <el-table-column prop="UserCount" label="使用人数">
                  </el-table-column>
                </el-table>
              </div>
            </div>
            <div class="rightsList">
              <div>购买是否需要提供身份信息</div>
              <div>
                {{ compileData.IsRealNameAuthentication ? "是" : "否" }}
              </div>
            </div>
            <div class="rightsList">
              <div>是否允许退款</div>
              <div>{{ compileData.IsRefund ? "是" : "否" }}</div>
            </div>

            <!-- <div class="rightsList">
              <div>海报</div>
              <div>
                <img class="rightsImage" :src="mainUrl" alt="" />
              </div>
            </div> -->
            <div class="rightsList">
              <div>权益主图</div>
              <div>
                <img class="rightsImage" :src="mainUrl" alt="" />
              </div>
            </div>
            <div class="rightsList">
              <div>权益附图</div>
              <div>
                <img class="rightsImage" v-for="(item, index) in imgsUrl" :key="index" :src="item.url" alt="" />
              </div>
            </div>
          </div>
          <div class="rights">
            <div>权益内容</div>
            <div class="rightsList rightsContent">
              <div>权益详情</div>
              <div v-html="compileData.Description"></div>
            </div>
            <div class="rightsList rightsContent">
              <div>使用规则</div>
              <div v-html="compileData.UseRuleDescription"></div>
            </div>
            <div class="rightsList">
              <div>退款是否需要审核</div>
              <div>{{ ["否", "是"][compileData.IsRefundAudit] }}</div>
            </div>

            <div class="rightsList rightsContent">
              <div :class="{ 'font-bold': compileData.TypeID == 2 }">
                退款规则
              </div>
              <div v-if="compileData.TypeID == 1 && refundList.length">
                <div v-for="(item, index) in refundList[0].list" :key="index">
                  {{ item.Name }}
                </div>
              </div>
              <div class="rule-box" v-else>
                <div class="rule-item" v-for="(item, index) in refundList" :key="index">
                  <div class="title">{{ item.title }}</div>
                  <div class="rules">
                    <div v-for="rule in item.list" :key="rule">
                      {{ rule.Name }}
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <br />
          <div class="rights">
            <div>审核历史</div>
            <div>
              <div class="history" v-if="historyData != false">
                <div class="audit-item" v-for="item in historyData" :key="item.ID">
                  <div class="audit-left"></div>
                  <div class="audit-right">
                    <div class="audit-right-box">
                      <div class="tag" :class="{
                        success: item.StatusID == 2,
                        error: item.StatusID == 3,
                        info: item.StatusID == 1
                      }">
                        {{ item.Status }}
                      </div>

                      <div class="text">{{ item.Opinions }}</div>
                    </div>
                    <div class="audit-right-box">
                      <div class="date">{{ item.CreateTime }}</div>
                      <div class="approver">{{ item.CreateUserID }}</div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="rights" v-if="compileData.Status != 5 && company == 1">
            <div>审核意见</div>
            <div style="margin: 2rem 0 2rem 2em;width: 95%;">
              <el-input type="textarea" :autosize="{ minRows: 4, maxRows: 6 }" placeholder="请输入审核意见内容"
                v-model="textarea">
              </el-input>
            </div>
          </div>
        </div>
        <!--  -->
        <div class="btn_cls" v-if="compileData.Status != 5 && company == 1">
          <div class="cancel_box reject" @click="amendType(4)" v-if="btnType == 0 || btnType == 2">
            驳回
          </div>
          <!--   -->
          <div class="cancel_box" @click="amendType(5)" v-if="btnType == 1 || btnType == 2">
            通过
          </div>
        </div>
      </div>
    </el-drawer>
    <!-- 合同 -->
    <el-drawer :visible.sync="contract" direction="rtl" size="45%" :with-header="false" :width="700">
      <div class="drawer_box">
        <div class="drawer_t">
          <div class="drawer_t_l">
            合同附件
          </div>
          <img class="drawer_t_r" src="/static/skin/herodoo/main/platform/home/img/guanbi.png" alt=""
            @click="contract = false" />
        </div>
        <iframe class="iframe" :src="filePath" frameborder="0"></iframe>
      </div>
    </el-drawer>
  </div>
</template>

<script>
export default {
  name: "bulkBuying",
  props: {
    compileData: {
      type: Object,
      default: {}
    },
    compileId: {
      type: [String, Number],
      default: ""
    },
    TypeID: {
      type: [String, Number],
      default: 1
    },
    btnType: {
      type: Number,
      default: 2
    }
  },
  data() {
    return {
      octopus: this.$parent.octopus,
      drawer: false,
      contract: false,
      alreadyList: [], // 自有权益
      buyList: [], //购买权益
      compileData: {}, //权益详情数据
      textarea: "", // 审核意见
      historyData: [], //审核历史
      filePath: "", //合同路径
      refundList: [], //退款规则
      company: 1
    };
  },
  watch: {
    compileId: {
      handler(v) {
        // this.getRefundRules();
      },
      deep: true
    },
    TypeID: {
      handler(v) {
        if (v == 2) {
          // this.getGroupData();
        }
      }
    }
  },

  computed: {
    mainUrl() {
      return this.compileData.MainPicturePath
        ? JSON.parse(this.compileData.MainPicturePath)[0].url
        : "";
    },
    imgsUrl() {
      return this.compileData.SecondaryPicturePath
        ? JSON.parse(this.compileData.SecondaryPicturePath)
        : [];
    }
    // totalMoney() {
    //     return this.goodsList.reduce((total, item) => {
    //         const combinedPrice = item.unitPrice * item.quantity;
    //         return total + combinedPrice;
    //     }, 0)
    // }
  },
  created() {
    this.company = this.octopus.passport.authorization.company;
  },
  mounted() { },
  methods: {
    toPlatformPrice() {
      //权益平台结算价格=所选自有权益的平台价格之和-（所选自有权益的平台价格之和*自有权益的权益平台服务费）+已购买权益平台价格之和
      let price = 0; // 权益平台结算价格
      this.alreadyList.map(v => {
        price +=
          (v.CostPrice - v.CostPrice * v.PlatformServiceRate) * v.EquityCount;
      });
      this.buyList.map(v => {
        price += v.CostPrice;
      });
      return price < 0 ? 0 : price.toFixed(2);
    },
    toEquityPrice() {
      let price = 0; // 小程序平台结算价格
      // {单个自有权益平台价-[单个自有权益平台价*(其小程序服务费+其平台服务费)]-（让利积分/10）}+{单个自有权益平台价-[单个自有权益平台价*(其小程序服务费+其平台服务费)]-（让利积分/10）}
      this.alreadyList.map(v => {
        price +=
          (v.CostPrice -
            v.CostPrice * (v.EquityServiceRate + v.PlatformServiceRate) -
            this.compileData.Integral / 10) *
          v.EquityCount;
      });

      this.buyList.map(v => {
        price += v.CostPrice;
      });
      return price < 0 ? 0 : price.toFixed(2);
    },

    statusType(status) {
      return status == 2 ? "通过" : status == 3 ? "驳回" : "";
    },

    drawerOp() {
      this.drawer = true;

      this.getHistoryList();
      if (this.compileData.TypeID == 2) {
        this.getGroupData();
      }

      this.alreadyList = [];
      this.buyList = [];
      this.getCompileData().then(res => {
        res.map(v => {
          v.CompanyID == this.compileData.CompanyID
            ? this.alreadyList.push(v)
            : this.buyList.push(v);
        });
        this.api_1241(this.compileData.EquityList, 2);
      });
    },
    drawerClose() {
      this.drawer = false;
    },
    amendType(type) {
      if (this.textarea.length != 0) { 
        this.$emit("amendType", { type: type, textarea: this.textarea });
        if (type == 4) {
          // 存入草稿 1
          this.api_748(4, type);
          // 获取用户组
          this.$utils.getGroupInfo(this, '超级管理员,高级管理员,业务管理员', this.compileData.CompanyID).then((res) => {
            console.log('发送消息的用户组：', res);
            // 发送消息 传值说明 模版ID ，消息类型 ，消息里的字段 ，创建用户ID，接收公司ID，接收群组ID
            res.length > 0 && this.$utils.sendMessageMulti(6, 6, { EquityName: this.compileData.Name },this.octopus.passport.id,  this.compileData.CompanyID, res, this)
          });

          return;
        }
        if (this.compileData.TypeID == 1) {
          this.api_CreateEquityRecord();
        } else {
          this.api_748(5, type);
        }

        // 获取用户组
        this.$utils.getGroupInfo(this, '超级管理员,高级管理员,业务管理员', this.compileData.CompanyID).then((res) => {
          console.log('发送消息的用户组：', res);
          // 发送消息 传值说明 模版ID ，消息类型 ，消息里的字段 ，创建用户ID，接收公司ID，接收群组ID
          res.length > 0 && this.$utils.sendMessageMulti(7, 6, { EquityName: this.compileData.Name },this.octopus.passport.id, this.compileData.CompanyID, res,  this)
        });
      } else {
        this.$message({
          type: "warning",
          message: "审核意见不能为空"
        });
      }
    },
    // 获取权益详情
    getCompileData() {
      return new Promise((resolve, reject) => {
        let o = this;
        o.octopus.request.api.post(
          "/Octopus/Engine/List",
          {
            id: 1184,
            cellData: [
              { name: "CostPrice" }, // 平台价格
              { name: "CompanyID" }, // 子权益公司ID
              { name: "FlagList" }, // 权益标签
              { name: "FlagListName" }, // 权益标签
              { name: "ID" }, // ID
              { name: "Name" }, // 权益标题
              { name: "SalePrice" }, // 市场价格
              { name: "SoldQuantity" }, // 已售数量
              { name: "TypeID" }, // 权益类型
              { name: "ExpireTime" }, // 到期时间
              { name: "EffectiveTime" }, // 生效时间
              { name: "InventoryQuantity" }, // 库存数量
              { name: "SoldQuantity" }, // 已售数量
              { name: "EquityCount" }, // 权益数量
              { name: "EquityServiceRate" }, // 小程序服务费
              { name: "PlatformServiceRate" }, // 平台服务费
              { name: "UserCount" } // 使用人数
            ],
            paramData: {
              ID: o.compileData.ID
            }
          },
          function (data) {
            if (data.status.code == 200) {
              resolve(data.content.queryData);
            } else {
              o.octopus.tips.error(data);
              reject(false);
            }
          }
        );
      });
    },
    // 获取组合权益数据
    getGroupData() {
      let o = this;
      this.alreadyList = [];
      this.buyList = [];
      o.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1358,
          cellData: [
            { name: "Address" }, // Address
            { name: "CompanyID" }, // CompanyID
            { name: "CostPrice" }, // CostPrice
            { name: "CreateTime" }, // CreateTime
            { name: "EffectiveTime" }, // EffectiveTime
            { name: "EquityFlagList" }, // EquityFlagList
            { name: "EquityFlagListName" }, // EquityFlagListName
            { name: "EquityList" }, // EquityList
            { name: "EquityListCount" }, // EquityListCount
            { name: "EquityServicePrice" }, // EquityServicePrice
            { name: "EquityServiceRate" }, // EquityServiceRate
            { name: "EquityShelfTime" }, // EquityShelfTime
            { name: "EquityStatus" }, // EquityStatus
            { name: "ExpireTime" }, // Expiretime
            { name: "ID" }, // ID
            { name: "Integral" }, // Integral
            { name: "InventoryQuantity" }, // InventoryQuantity
            { name: "IsOpenSale" }, // IsOpenSale
            { name: "IsRefund" }, // IsRefund
            { name: "MainPicturePath" }, // MainPicturePath
            { name: "MinimumQuantity" }, // MinimumQuantity
            { name: "Name" }, // Name
            { name: "PlatformServicePrice" }, // PlatformServicePrice
            { name: "PlatformServiceRate" }, // PlatformServiceRate
            { name: "PlatformShelfTime" }, // PlatformShelfTime
            { name: "PlatformStatus" }, // PlatformStatus
            { name: "ProductCode" }, // ProductCode
            { name: "ProductFlagList" }, // ProductFlagList
            { name: "ProductFlagListName" }, // ProductFlagListName
            { name: "ProductID" }, // ProductID
            { name: "SalePrice" }, // SalePrice
            { name: "SecondaryPicturePath" }, // SecondaryPicturePath
            { name: "SoldQuantity" }, // SoldQuantity
            { name: "Status" }, // Status
            { name: "StatusName" }, // StatusName
            { name: "TransferRuleID" }, // TransferRuleID
            { name: "TransferRuleIDName" }, // TransferRuleIDName
            { name: "TypeID" }, // TypeID
            { name: "UsersCount" }, // UsersCount
            { name: "Visits" }, // Visits
            { name: "IsRealNameAuthentication" } // Visits
          ],
          paramData: {
            CompanyID: this.compileData.CompanyID, // this.octopus.passport.authorization.company,
            ID: this.compileData.ID,
            UserID: this.octopus.passport.id
          }
        },
        data => {
          if (data.status.code == 200) {
            this.compileData.IsRealNameAuthentication =
              data.content.queryData[0].IsRealNameAuthentication;
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },

    // 获取审核历史
    getHistoryList() {
      let o = this;
      this.alreadyList = [];
      this.buyList = [];
      o.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1205,
          cellData: [
            { name: "CreateTime" }, // 时间
            { name: "ID" }, // ID
            { name: "Opinions" }, // 审核内容
            { name: "Status" }, // 审核状态
            { name: "StatusID" }, // 审核状态
            { name: "CreateUserID" } //创建人
          ],
          paramData: {
            EquityID: this.compileData.ID
          }
        },
        function (data) {
          if (data.status.code == 200) {
            o.historyData = data.content.queryData;
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },

    // 获取退款规则
    getRefundRules() {
      this.refundList = [];
      let o = this;
      let filterKey = "=";
      let filterValue = this.compileData.ID;
      if (this.compileData.TypeID == 2) {
        filterKey = "in";
        const arr = [...this.alreadyList, ...this.buyList];
        filterValue = arr.map(item => item.ID);
      }
      o.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1210,
          cellData: [
            { name: "CompanyID" }, // 公司
            { name: "CreateTime" }, // 创建时间
            { name: "CreateUserID" }, // 创建人
            {
              name: "EquityID",
              filterKey: filterKey,
              filterValue: filterValue
            }, // 权益
            { name: "EquityName" }, // 权益
            { name: "ID" }, // ID
            { name: "InventoryID" }, // 库存
            { name: "Name" }, // 规则名称
            { name: "ProductID" }, // 产品ID
            { name: "ServiceCharge" }, // 服务费
            { name: "Status" }, // 状态
            { name: "TimeLimit" }, // 时间限制
            { name: "TypeID" }, // 类型ID
            { name: "UpdateTime" } // 修改时间
          ]
        },
        function (data) {
          if (data.status.code == 200) {
            if (o.compileData.TypeID == 1) {
              if (data.content.queryData.length) {
                o.refundList.push({
                  title: data.content.queryData[0].EquityName,
                  list: data.content.queryData
                });
              }
            } else {
              const obj = {};
              data.content.queryData.map(item => {
                if (!obj[item.EquityID]) {
                  obj[item.EquityID] = [];
                }
                obj[item.EquityID].push({
                  title: item.EquityName,
                  list: item
                });
              });
              Object.keys(obj).map(key => {
                o.refundList.push({
                  ID: key,
                  list: obj[key]
                });
              });
            }
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },

    // 添加审核历史
    createAuditStatus(type, text = null) {
      let status = null,
        o = this; // 1未提交  2审核中   4审核未通过   5未启用(审核通过)   6小程序启用     7平台启用
      type == 5 && (status = 2);
      type == 4 && (status = 3);
      o.octopus.request.api.post(
        "/Octopus/Engine/Item",
        {
          id: 1196,
          type: "CREATE",
          cellData: [
            { name: "EquityID", defaultValue: this.compileData.ID }, //权益ID
            {
              name: "CreateTime",
              defaultValue:
                new Date().toJSON().substring(0, 10) +
                " " +
                new Date().toTimeString().substring(0, 8)
            }, // 时间
            {
              name: "Opinions",
              defaultValue: status == 2 ? "审核通过" : !text ? o.textarea : text
            }, // 审核内容
            { name: "Status", defaultValue: status }, // 审核状态
            { name: "CreateUserID", defaultValue: o.octopus.passport.id } //创建人
          ]
        },
        data => {
          if (data.status.code == 200) {
            o.$emit("refresh");
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },
    // 集团直接 添加库存
    api_CreateEquityRecord() {
      let o = this;
      o.octopus.tools.openAPI(
        "/ESB/AIGC/CreateEquityRecord",
        {
          companyID: o.compileData.CompanyID, // 权益所属公司ID
          equityID: o.compileData.ID, // 权益ID
          quantity: o.compileData.InventoryQuantity, // 单个权益数量
          createUserID: o.octopus.passport.id // 创建人
        },
        datas => {
          if (datas.status.code == 200) {
            o.$message({
              message: "操作成功",
              type: "success"
            });
            o.$emit("createdSuccess", 0);
            o.createAuditStatus(5)
          } else {
            o.octopus.tips.error(datas.status.message);
          }
        }
      );
    },
    showContract() {
      try {
        let _pathData = JSON.parse(this.compileData.FilePath)[0];
        let _this = this;
        let file_path = _pathData.url.substring(
          _pathData.url.indexOf("upload") + 6
        );
        let view_path =
          _this.octopus.config.url +
          "/Octopus/Engine/Viewer/" +
          _pathData.name +
          "?" +
          "path=" +
          file_path +
          "&access_token=" +
          _this.octopus.passport.token;

        _this.filePath = view_path;
        this.contract = true;
      } catch (e) {
        console.log(e);
      }
    },
    hideContract() {
      this.contract = false;
    },
    api_748(status = 4, type, text) {
      this.octopus.request.api.post(
        "/Octopus/Engine/Item",
        {
          id: 748,
          type: "UPDATE",
          value: this.compileData.ID,
          cellData: [
            { name: "Status", defaultValue: status } // 权益状态（保存未提交（草稿箱）、已提交/待审核、审核通过、审核未通过、未启用，启用、已售完、到期）
          ]
        },
        data => {
          if (data.status.code == 200) {
            type == 4 && this.createAuditStatus(4, text);
            type == 5 && this.api_cmbEquity();
            this.$emit("refresh");
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },
    // 组合权益插入库存
    api_cmbEquity() {
      let list = [];
      this.alreadyList.map(v => {
        list.push({ equityID: v.ID, quantity: v.EquityCount });
      });
      this.buyList.map(v => {
        list.push({ equityID: v.ID, quantity: v.EquityCount });
      });
      this.octopus.tools.openAPI(
        "/ESB/AIGC/cmbEquity",
        {
          userId: this.octopus.passport.id,
          equityId: this.compileData.ID, //组合权益ID
          typeId: 2, //
          companyId: this.compileData.CompanyID, // 公司ID
          quantity: this.compileData.InventoryQuantity, //组合权益数量
          baseEquityList: list, // 组合权益的子权益
          channelId: "2" // 页面不同 创建页面传1 ，权益审核传2，库存管理传3
        },
        datas => {
          if (datas.content.status.code == 200) {
            this.$message({
              message: "操作成功 ",
              type: "success"
            });
            this.createAuditStatus(5)
          } else {
            // this.octopus.tips.error(datas.content.content);
            this.is_turn_back(datas.content.content);
          }
        }
      );
    },
    is_turn_back(text) {
      this.$confirm(`${text}`, "提示", {
        confirmButtonText: "驳回",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.api_748(4, 4, text);
        })
        .catch(() => {
          this.api_748(2, 2);
        });
    },
    // 退款规则
    api_1241(str, type = 2) {
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1241,
          cellData: [
            { name: "CompanyID" }, // 公司ID
            { name: "CreateTime" }, // 创建时间
            { name: "CreateUserID" }, // 创建人
            { name: "EquityID" }, // 权益ID
            { name: "EquityName" }, // 权益名称
            { name: "ID" }, // ID
            { name: "InventoryID" }, // 库存
            { name: "Name" }, // 规则名称
            { name: "ProductID" }, // 产品
            { name: "ServiceCharge" }, // 手续费（%）
            { name: "Status" }, // 是否启用
            { name: "TimeLimit" }, // 时限（默认小时）
            { name: "TypeID" }, // 规则类型（1小时  2天）
            { name: "UpdateTime" } // 修改时间
          ],
          paramData: {
            EquityID: str
          }
        },
        datas => {
          if (datas.status.code == 200) {
            this.refundList = [];
            let item = datas.content.queryData;
            let arr = [...this.alreadyList, ...this.buyList];
            // console.log(item, "[[]]", this.alreadyList, arr);
            arr.map(v => {
              let find = item.filter(x => v.ID == x.EquityID)
              if (find) {
                this.refundList.push({
                  title: v.Name,
                  list: find
                })
              } else {
                this.refundList.push({
                  title: v.Name,
                  list: []
                })
              }
            })
            // let arr = str.split(",");
            // arr.map(v => {
            //   let find = item.filter(x => x.EquityID == v);
            //   this.refundRules.push({
            //     Name: find[0].EquityName,
            //     list: [...find]
            //   });
            // });
          } else {
            this.octopus.tips.error(datas);
          }
        }
      );
    }
  }
};
</script>
<style scoped>
.flex {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.rightsImage {
  width: 14rem;
  height: 14rem;
  border-radius: 1rem;
  display: inline-block;
  margin-right: 1rem;
}

.rightsList {
  display: flex;
  margin-left: 2em;
  margin: 2rem 0 2rem 2em;
}

.rightsContent>>>img {
  width: 100%;
}

.rightsList>div:nth-child(1) {
  width: 25%;
}

.rightsList>div:nth-child(2) {
  flex: 1;
}

.rightsList .rights-tag {
  margin-right: 15px;
  border-radius: 2px;
  border: 1px solid #3f9eff;
  color: #3f9eff;
  padding: 1px 2px;
  font-size: 1rem;
  /* display: flex; */
  justify-content: center;
  align-items: center;
}

.rightsList .auth-tag {
  margin-right: 10px;
  border: 1px solid #a570e9;
  background-color: #a570e9;
  color: #fff;
}

.deadlin .title {
  font-size: 1.8rem;
  font-weight: bold;
}

.deadline-box {
  border: 1px solid rgba(0, 0, 0, 0.8);
  border-radius: 6px;
  padding: 4px 0 4px 4px;
  margin-top: 4px;
}

.rightsContent {
  flex-direction: column;
}

.rightsContent img {
  width: 100%;
}

.rightsContent>div:nth-child(2) {
  margin-top: 10px;
  text-indent: 2em;
}

.rights>div:nth-child(1) {
  font-size: 1.8rem;
  font-weight: bold;
}

.drawer_box {
  padding: 3rem 0.8rem 3rem 0;
  height: calc(100% - 5rem);
  display: flex;
  flex-direction: column;
}

.drawer_t {
  padding: 0 2.8rem;
  display: flex;
  justify-content: space-between;
}

.drawer_t_l {
  display: flex;
  align-items: center;
  font-size: 1.8rem;
  font-weight: bold;
}

.drawer_t_l_img {
  width: 2.8rem;
  margin-right: 1rem;
}

.drawer_t_r {
  width: 3rem;
  height: 3rem;
  cursor: pointer;
}

.drawer_c {
  font-size: 1.6rem;
  height: 85vh;
  overflow: auto;
  margin-top: 3rem;
  padding: 0 3rem;
  background-color: #fff;
}

.tableList {
  width: 100%;
  max-height: 34vh;
  overflow: auto;
  margin-bottom: 1rem;
}

.tableList>div {
  display: flex;
  font-size: 1.6rem;
  justify-content: space-between;
  text-align: center;
}

.tableList .table_title {
  font-weight: 700;
  background-color: #f7f9fb;
  line-height: 5rem;
  padding: 0 0.8rem;
  /* text-align: left; */
}

.tableList .table_list {
  padding: 1rem 0.8rem;
  margin: 1rem 0;
  line-height: 8rem;
  box-shadow: 0px 2px 6px 0px rgba(180, 171, 206, 0.4);
}

.tableList .table_list .img_box {
  display: flex;
}

.tableList .table_list img {
  width: 8rem;
  height: 8rem;
  border-radius: 1rem;
  margin-right: 2rem;
}

.tableList .table_list .img_box .text {
  display: flex;
  justify-content: center;
  flex-flow: column;
  line-height: 2rem;
  text-align: left;
}

.tableList .table_list .lable_list {
  display: flex;
  justify-content: center;
  flex-flow: column;
  line-height: 2.5rem;
  text-align: left;
  font-size: 1.8rem;
}

/* .tableList .table_list .lable_list{
color: #c3c3c3;
font-size: 1.3rem;
text-align: left;
} */
.tableList .table_list .lable_list span {
  border: 1px solid #c3c3c3;
  padding: 0 0.7rem;
  border-radius: 0.5rem;
  color: #c3c3c3;
  font-size: 1.3rem;
  text-align: left;
  margin: 0.2rem;
  display: inline-block;
}

.btn_cls {
  position: absolute;
  bottom: 1rem;
  right: 2rem;
  display: flex;
}

.cancel_box {
  line-height: 4rem;
  background-color: #f78c51;
  color: #fff;
  margin: 0 1rem;
  padding: 0 3rem;
  border-radius: 0.5rem;

  cursor: pointer;
}

.reject {
  background-color: #2e3037;
}

.type_tab {
  width: 100%;
  border-bottom: 1px solid #c3c3c3;
  display: flex;
}

.type_tab img {
  width: 2rem;
  vertical-align: middle;
  margin-right: 1rem;
  margin-top: -0.2rem;
}

.type_tab>div {
  font-size: 1.6rem;
  /* height: 4rem; */
  line-height: 4rem;
  margin-right: 4rem;
  cursor: pointer;
}

.type_tab_color {
  border-bottom: 3px solid #f78c51;
}

.pay_code {
  display: flex;
  margin-top: 1.5rem;
  text-align: center;
}

.pay_code .img_box img {
  width: 17rem;
}

.pay_code .text_box {
  text-align: left;
  margin-left: 2rem;
  display: flex;
  justify-content: center;
  flex-flow: column;
  font-size: 1.8rem;
}

.pay_code .text_box>div {
  margin: 1.5rem 0;
}

.pay_code .text_box span {
  margin: 0 1rem;
}

.font-bold {
  font-size: 1.6rem;
  font-weight: bold;
}

.rights_son_box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.rights_son {
  width: 100%;
  border-radius: 6px;
  padding: 6px 8px;
  box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.rights_son:not(:first-child) {
  margin-top: 10px;
}

.rights_son .title {
  font-size: 1.6rem;
  font-weight: bold;
}

.rights_son .date {
  font-size: 1.2rem;
  margin-top: 5px;
}

.rights_son .repert-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.rights_son .repert-right {
  font-size: 2em;
  font-weight: bold;
  color: #ff4f17;
}

.contract-btn {
  margin-left: 3px;
  background-color: #f88c51;
  padding: 2px 4px;
  border-radius: 4px;
  border: 0;
  color: #fff;
}

.history {
  margin-left: 2em;
  margin-top: 1em;
}

.history .audit-item {
  display: flex;
}

.history .audit-item .audit-left {
  position: relative;
  width: 2px;
  height: 60px;
  border-radius: 4px;
  background-color: #dfdfdf;
}

.history .audit-item .audit-left::before {
  position: absolute;
  top: 15px;
  left: 50%;
  transform: translateX(-50%);
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #ff8755;
}

.history .audit-item .audit-right {
  margin-left: 16px;
}

.history .audit-item .audit-right .audit-right-box {
  display: flex;
  align-items: center;
  margin-top: 15px;
}

.history .audit-item .audit-right .audit-right-box:not(:first-child) {
  margin-top: 8px;
}

.history .audit-item .audit-right .audit-right-box .tag {
  font-size: 1em;
  padding: 1px 2px;
  color: #fff;
  border-radius: 2px;
  margin-right: 6px;
}

.history .audit-item .audit-right .audit-right-box .tag.success {
  background-color: #3fdf72;
}

.history .audit-item .audit-right .audit-right-box .tag.info {
  background-color: #43b4ff;
}

.history .audit-item .audit-right .audit-right-box .tag.error {
  background-color: #f75352;
}

.history .audit-item .audit-right .audit-right-box .date {
  margin-right: 6px;
}

.iframe {
  width: 100%;
  height: 100%;
}

.rules {
  border: 1px solid #000;
  border-radius: 10px;
  padding: 5px;
  font-size: 1rem;
}
</style>
